$NG.AllReady(function (
	page,
	{
		useValuesChange,
		useClick,
		useUpdateRow,
		useUpdateRows,
		useDataIndexChange,
		useBeforeClick,
	}
) {
	var mstform = $NG.getCmpApi("p_form_supply_spec_apply_m");

	var tab = $NG.getCmpApi("p_form_supply_spec_apply_d"); //案例明细
	var tab1 = $NG.getCmpApi("p_form_supply_spec_apply_d1"); //证照信息
	var tab2 = $NG.getCmpApi("p_form_supply_spec_apply_d2"); //资质信息
	var tab4 = $NG.getCmpApi("p_form_supply_spec_apply_d4"); //供应物料
	var tab5 = $NG.getCmpApi("p_form_supply_spec_apply_d5"); //联系人信息

	if ($NG.getCmpApi("p_form_supply_spec_apply_m")) {
		if (mstform.getItem("u_use_pc").getValue()) {
			getPtInfoByPhid();
		}
	}

	if (page.oType == "add") {
	}
	//表头字段变化逻辑BEGIN
	useValuesChange(({ args }) => {
		getPtInfoByPhid();
	}, "p_form_supply_spec_apply_m.u_use_pc");

	//表头字段变化逻辑BEGIN
	useValuesChange(({ args }) => {
		console.log(args, "单位名称");

		//监听单位名称
		$NG.execServer(
			"fbsrdxx",
			{ phid: args[0].u_unit_name.origin.phid },
			function (res) {
				const datas = JSON.parse(res.data)[0].extendObjects;
				console.log(datas, "data11111s");

				if (datas.region_id) {
					console.log(datas.region_id, "datas.region_id");
					$NG.execServer("getAddressToId", { phid: datas.region_id }, function (res2) {
						const data2 = JSON.parse(res2.data)[0].extendObjects; //单返回值
						console.log(data2, "data2");
						$NG.updateState((updater) => {
							updater.data.p_form_supply_spec_apply_m.setProps({
								u_nation: {
									value: data2.nationno,
									label: data2.nationname,
								},
								u_province: {
									value: data2.provinceno,
									label: data2.provincename,
								},
								u_city: {
									value: data2.cityno,
									label: data2.cityname,
								},
								u_region: {
									value: data2.regionno,
									label: data2.regionname,
								},
							});
						});
					});
				}
				//功能扩展
				$NG.execServer(
					"searchIDBank",
					{ phid: datas.taxbank_id },
					function (res1) {
						const data = JSON.parse(res1.data)[0].extendObjects; //单返回值
						console.log(data, "data");
						$NG.updateState((updater) => {
							updater.data.p_form_supply_spec_apply_m.setProps({
								u_swyh: {
									value: data.phid,
									label: data.bankno,
								}, //税务银行行号11
							});
						});
					}
				);

				$NG.updateState((updater) => {
					updater.data.p_form_supply_spec_apply_m.setProps({
						// u_contacts: datas.linkman, //联系人
						// u_contacts_phone: datas.phone, //联系电话
						// u_name1: datas.compname, //

						u_id_card: datas.iden_card_id, //法人身份证身份证
						u_nssflx: datas.taxpayertype, //纳税身份类型11
						u_nsr_name: datas.tax_person, //纳税人姓名11

						u_swdjdz: datas.tax_register_addr, //税务地址名称11
						u_swyhmc: datas.taxbank_name, //税务银行名称11
						u_swdjzh: datas.taxaccount_no, //税务登记账号11
						u_swdjdh: datas.phone, //税务登记电话
						u_usci: datas.three_to_one, //社会信用代码11
						u_zcsj: datas.regdate, //成立日期11
						u_rygm: datas.firm_size, //公司规模11
						u_frdb: datas.psn, //法人11
						u_zczj: datas.reg_fund, //注册资本11
					});
				});
				console.log(datas.taxbank_id, "datas.taxbank_id");
			}
		);
	}, "p_form_supply_spec_apply_m.u_unit_name");

	useUpdateRows(({ args, table }) => {
		updataRowStatus();
	}, "p_form_supply_spec_apply_d");
	//物料明细..
	useUpdateRow(({ args, table }) => {
		const record = args[0];
		console.log(args[0], "获取值");
		console.log(args[0].u_item_name, "查询id");
		$NG.execServer(
			"autoSelectType",
			{ id: args[0].u_item_name },
			function (res) {
				let resWzxlData = JSON.parse(res.data)[0].extendObjects;
				console.log(res.status, "返回值resWzxlData");
				if (res.status == "success") {
					$NG.execServer(
						"getAutoType",
						{ phid: resWzxlData.phid_resbs },
						function (res) {
							const datas = JSON.parse(res.data)[0].extendObjects;
							console.log(datas, "获取值datas");
							record.u_wzzl = datas.f_phid;
							record.u_wzzl_EXName = datas.fname;
							record.u_wzdl = datas.g_phid;
							record.u_wzdl_EXName = datas.gname;
							record.u_wzxl = resWzxlData.phid_resbs;
							record.u_wzxl_EXName = datas.name;

							tab4.updateRow(record);
							tab4.refreshView();
							getRuleInfoTableData(record.u_wzdl, record.u_is_yc, record);
						}
					);
				} else {
					$NG.alert("未查询到该物资类型");
				}
			}
		);
		// console.log(getItemValue("u_brand"), "获取值getItemValue(u_brand)");
		// record.u_brand = getItemValue("u_brand");
		console.log(record, "recordrecordrecord");

		tab4.updateRow(record);
		tab4.refreshView();
		// u_cl_data;成立日期

		// u_pl u_dlyc u_clnx u_zczj;
	}, "p_form_supply_spec_apply_d4");
	function getPtInfoByPhid() {
		if (mstform.getItem("u_use_pc").getValue()) {
			$NG.execServer(
				"getPtInfoByPhid",
				{ phid: mstform.getItem("u_use_pc").getValue() },
				function (res) {
					const datas = JSON.parse(res.data)[0].extendObjects;
					console.log(datas, "datas");
					//帮助字段赋值
					$NG.updateState((updater) => {
						updater.data.p_form_supply_spec_apply_m.setProps({
							u_division: {
								//事业部or组织
								value: datas.org_phid,
								label: datas.org_name,
							},
							u_regional_center: {
								//区域中心
								value: datas.regional_center_phid,
								label: datas.regional_center_name,
							},
							u_product_line: {
								//产品线
								value: datas.midwife_phid,
								label: datas.midwife_name,
							},
						});
					});
				}
			);
		}
	}
});
